
<template>
	<div class="index">

		<div class="center">
			<left></left>
			<div class="right">
          <top></top>
          <div class="hei10"></div>
          <div class="where" style="background: #fff; padding: 10px 30px; font-size: 14px; color: #595959;">当前位置：分销后台><router-link to="/mySupplier" style="color: #409eff;">我的供应商</router-link></div>
          <div class="hei10"></div>
<div class="addpro">
                    <div v-loading = "loading">
                        <div class="step">
                            <div class="tilte">修改基础产品信息<span>?</span></div>
                            <div class="con">
                                <el-form ref="form" :rules="rules" @submit.native.prevent :model="form" label-width="120px">
                                    <div class="flex w330">
                                        <el-form-item label="运营商:" prop="operator">
                                            <el-select v-model="form.operator" placeholder="请选择运营商:">
                                                <el-option v-for="item in sanlist" :key="item.id" :label="item.name" :value="item.id"></el-option>
                                            </el-select>
                                        </el-form-item>
                                        <el-form-item label="产品类型:">
                                            <el-select v-model="form.plan_type_id" placeholder="请选择产品类型:">
                                              <el-option v-for="item in typelist" :key="item.id" :label="item.name" :value="item.id"></el-option>
                                            </el-select>
                                            <el-button type="primary" @click="taglog = true">自定义</el-button>
                                        </el-form-item>
                                    </div>
                                    <div class="flex w330">
                                        <el-form-item label="产品名称:" prop="name">
                                            <el-input v-model="form.name" :class="{redbor:!sub1}"  @input="nijiushiwodeweiyi1" placeholder="产品名称"></el-input>
                                        </el-form-item>
                                        <el-form-item label="产品编号:" prop="sku">
                                            <el-input v-model="form.sku" :class="{redbor:!sub2}" placeholder="产品编号" @input="nijiushiwodeweiyi2"></el-input>
                                        </el-form-item>
                                    </div>
                                    <el-form-item label="归属地:" class="w330">
                                        <el-cascader @change="changeaddress" v-model="form.citys" :options="citylist"></el-cascader>
                                    </el-form-item>
                                    <el-form-item label="生产定义:">
                                        <div class="ori">
                                                <el-form-item label="是否需要身份证号码:">
                                                    <el-radio-group v-model="form.need_num">
                                                        <el-radio label="0">不需要</el-radio>
                                                        <el-radio label="1">需要</el-radio>
                                                    </el-radio-group>
                                                    <el-tooltip class="item" effect="light" content="下单是否需要身份证号码，选择后订单必须有身份证号才会进入审核生产。" placement="top">
                                                        <span class="wenhao">?</span>
                                                    </el-tooltip>
                                                </el-form-item>
                                                <el-form-item label="是否需要身份证照片:">
                                                    <el-radio-group v-model="form.real_name_type">
                                                        <el-radio label="1">不需要</el-radio>
                                                        <el-radio label="0">需要</el-radio>
                                                    </el-radio-group>
                                                    <el-tooltip class="item" effect="light" content="下单是否需要三张身份证照片，选择后订单必须有照片才会进入审核生产。" placement="top">
                                                        <span class="wenhao">?</span>
                                                    </el-tooltip>
                                                </el-form-item>
                                                <el-form-item label="生产地址:">
                                                    <el-input v-model="form.produce_address" placeholder="生产地址"></el-input>
                                                </el-form-item>
                                        </div>
                                    </el-form-item>
                                    <el-form-item label="限制条件:">
                                        <div class="ori">
                                            <el-form-item label="不发货地址设置:">
                                                <el-button type="primary"  size="mini" plain @click="keylog = true">已设置{{mingan.citys.length}}个</el-button>
                                            </el-form-item>
                                            <el-form-item class="age" label="年龄限制(周岁):">
                                                <el-input v-model="form.min_age" placeholder="最小年龄"></el-input>
                                                ——
                                                <el-input v-model="form.max_age" placeholder="最大年龄"></el-input>
                                            </el-form-item>
                                            <div class="xiaoming">
												<el-form-item label="单人开卡数量限制:">
													<el-select v-model="form.max_purchase" placeholder="请选择最大开卡数量:">
														<el-option label="不限制" value="-1"></el-option>
														<el-option label="1" value="1"></el-option>
														<el-option label="2" value="2"></el-option>
														<el-option label="3" value="3"></el-option>
														<el-option label="4" value="4"></el-option>
														<el-option label="5" value="5"></el-option>
													</el-select>
												</el-form-item>

												<!-- 小鸣莺专用 -->
												<el-form-item label="检测周期:">
													<el-select v-model="xiaomingtime" placeholder="检测周期:">
														<el-option label="不限制" value="0"></el-option>
														<el-option label="1个月" value="1"></el-option>
														<el-option label="2个月" value="2"></el-option>
														<el-option label="3个月" value="3"></el-option>
														<el-option label="4个月" value="4"></el-option>
														<el-option label="5个月" value="5"></el-option>
														<el-option label="6个月" value="6"></el-option>
														<el-option label="7个月" value="7"></el-option>
														<el-option label="8个月" value="8"></el-option>
														<el-option label="9个月" value="9"></el-option>
														<el-option label="10个月" value="10"></el-option>
														<el-option label="11个月" value="11"></el-option>
														<el-option label="12个月" value="12"></el-option>
													</el-select>
												</el-form-item>
											</div>
                                        </div>
                                    </el-form-item>
                                    <el-form-item class="w480" label="生产备注:">
                                        <el-input v-model="form.produce_remark" placeholder="生产备注"></el-input>
                                    </el-form-item>
                                    <el-form-item class="w480"  label="结算规则:">
                                        <el-input v-model="form.commission_rule" placeholder="结算规则"></el-input>
                                    </el-form-item>
                                    <el-form-item label="物流公司:">
                                        <el-select v-model="form.tracking_company_id" placeholder="物流公司:">
                                          <el-option v-for="item in tracklist" :key="item.id" :label="item.company" :value="item.id"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-form>
                            </div>
                        </div>

                        <div class="step" v-if="!showmoney">
                            <div class="tilte">关联号池设置</div>
                            <div class="con haochi">
                                <el-form ref="form" @submit.native.prevent :model="form" label-width="80px">
                                    <el-form-item>
                                        <div class="flex" style="margin-bottom: 30px;">
                                            <el-radio v-model="pool" label="1">关联号库（提供选号）</el-radio>
                                            <el-select v-model="form.pool_id" placeholder="请选择号库:">
                                              <el-option v-for="item in poollist" :key="item.id" :label="item.name" :value="item.id"></el-option>
                                            </el-select>
                                        </div>
                                        <div class="flex"><el-radio v-model="pool" label="2">无（不提供选号）</el-radio></div>
                                    </el-form-item>
                                </el-form>
                            </div>
                        </div>

                        <div class="step">
                            <div class="tilte">定义商品销售页信息</div>
                            <div class="con">
                                <el-form ref="form" :rules="rules" @submit.native.prevent :model="shopform" label-width="180px">
                                    <!-- <el-form-item label="抓单识别:"  prop="randomnum">
                                        {{randomnum}}
                                       <el-button plain type="primary" size="small" @click="randomlog = true">自定义</el-button>
                                        <el-tooltip class="item" effect="light" content="如果要使用自动抓单系统的话，请在电商平台将该码粘贴到产品后台的“货号（商品编码）”处。每个产品都有唯一标识" placement="top">
                                            <span class="wenhao">?</span>
                                        </el-tooltip>
                                    </el-form-item> -->

                                    <el-form-item label="商家编码（抓单标识）:" prop="sku" style="width: 450px;">
                                        <div style="display: flex;">
                                            <el-input v-model="form.sku" disabled=""></el-input>
                                            <el-tooltip class="item" effect="light" content="如果要使用自动抓单系统的话，请在电商平台将该码粘贴到产品后台的“货号（商品编码）”处。每个产品都有唯一标识" placement="top">
                                                <span class="wenhao" style="height: 18px; position: relative; top: 5px;">?</span>
                                            </el-tooltip>
                                        </div>
                                    </el-form-item>
                                    <!-- <el-form-item label="京东特有(必须三位):" style="width: 450px;">
                                        <el-input v-model="jingdongrandom" maxlength="3" :class="{redbor:!sub4}" @input="nijiushiwodeweiyi4" placeholder="请输入京东特用抓单码"></el-input>
                                    </el-form-item> -->
                                    <div class="flex w330">
                                        <el-form-item label="商品名称:">
                                            <el-input v-model="form.name"  prop="title" disabled placeholder="根据产品名自定义"></el-input>
                                        </el-form-item>
                                        <el-tooltip class="item" effect="light" content="对外展示的产品标题，能清晰描述概括产品，例：北京19元月租大王卡赠2GB流量" placement="top">
                                            <span class="wenhao" style="display: block; height: 29px; width: 29px; padding: 0; line-height: 29px; margin-top: 5px;">?</span>
                                        </el-tooltip>
                                    </div>
									<div class="flex w330" style="align-items: center; margin-bottom: 0px;">
										<el-form-item label="商品注意点:">
											<el-input v-model="shopform.points" placeholder="输入商品注意点"></el-input>
										</el-form-item>
									</div>
                                    <div class="flex w330">
                                        <el-form-item label="商品卖点:">
                                            <el-input v-model="shopform.selling_point" placeholder="输入卖点，使用逗号隔开"></el-input>
                                        </el-form-item>
                                        <el-tooltip class="item" effect="light" content="不超过3组词，例：资费低，流量大，免月租等，不宜过长" placement="top">
                                            <span class="wenhao" style="display: block; height: 29px; width: 29px; padding: 0; line-height: 29px; margin-top: 5px;">?</span>
                                        </el-tooltip>
                                    </div>
                                    <div class="flex w480">
                                        <el-form-item label="结算要求:">
                                            <el-input v-model="shopform.commission_rule" placeholder="对外展示"></el-input>
                                        </el-form-item>
                                    </div>
                                    <el-form-item label="销售页上传照片:">
                                        <el-radio-group v-model="shopform.is_need_photo"  prop="is_need_photo">
                                            <el-radio label="0">无需上传</el-radio>
                                            <el-radio label="1">需要上传</el-radio>
                                        </el-radio-group>
                                        <el-tooltip class="item" effect="light" content="仅设置是否需要在销售页下单时上传照片，选择无需上传可在批量上传照片处另行导入。" placement="top">
                                            <span class="wenhao">?</span>
                                        </el-tooltip>
                                    </el-form-item>
                                    <div class="flex">
                                        <el-form-item label="产品主图:"  prop="img">
                                            <el-upload  class="avatar-uploader" action="https://jsonplaceholder.typicode.com/posts/" :on-change="uploadok" :auto-upload="false" :show-file-list="false" >
                                              <img v-if="shopform.image1" :src="shopform.image1" class="avatar">
                                              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                            </el-upload>
                                        </el-form-item>
                                    </div>

                                    <el-form-item label="产品详情:" prop="edit">
                                        <div id="editor">

                                        </div>
                                    </el-form-item>
                                    <!-- <el-form-item label="修改摘要:">
                                        <el-input type="textarea" v-model="abstract"></el-input>
                                    </el-form-item> -->
                                </el-form>
                            </div>
                        </div>
                        <div class="step" style="text-align: center;"><el-button type="danger" @click="productsave()">确认修改</el-button></div>
                    </div>
				</div>
			</div>
		</div>
        <el-dialog title="关键词设置":visible.sync="keylog" width="700px;">
        	  <div style="display: flex; justify-content: space-between;">
                  <div style="flex-basis: 370px; line-height: 30px;">
                        <div>关键词尽量采用：地市名称和区域名称，确保系统精准检查</div>
                        <div>例：河南开封市尉氏县蔡庄镇 关键词：开封市，蔡庄镇</div>
                  </div>
                  <div class="keyd" style="flex-basis: 200px;">
                      <upload-excel-component @on-selected-file="exportData" buttonName="导入" class="nobtn"></upload-excel-component>
                      <el-button type="primary"  size="mini" plain @click="xiazai">下载模板</el-button>
                  </div>
              </div>
              <div>
                    <div style="display: flex; background: #E5E5E5; color: #707070; text-align: center; line-height: 45px; margin-top: 20px;">
                          <div style="flex: 1;">原敏感地区录入</div>
                          <div style="flex: 1;">关键词编辑</div>
                    </div>
                    <div class="keylist"  style="max-height: 350px; overflow: auto;">
                        <div style="display: flex; border: 1px #EAEAEA solid;" v-for="(item,i) in keyv">
                            <div style="flex: 1; padding:10px;"><el-input v-model="item.key1" placeholder="请输入内容"></el-input></div>
                            <div style="flex: 1; display: flex; padding:10px;">
                                <el-input v-model="item.key2" placeholder="请输入内容"></el-input>
                                <el-input v-model="item.key3" placeholder="请输入内容"></el-input>
                                <i class="el-icon-delete" @click="keydel(i)" style=" margin-left: 5px; padding-top: 8px; cursor: pointer;"></i>
                            </div>
                        </div>
                    </div>
                    <div style="display: flex; justify-content: center; margin-top: 20px;"><el-button type="primary"  size="mini" @click="addkey">新增关键词</el-button></div>

              </div>
        	  <span slot="footer" class="dialog-footer">
        		<el-button @click="keylog = false">取 消</el-button>
        		<el-button type="primary" @click="keygo">确 定</el-button>
        	  </span>
        </el-dialog>
        <el-dialog title="自定义抓单ID":visible.sync="randomlog" width="400px">
        	  <div class="randomdiv">
                  <el-input v-model="randomvalue" @input="randomnumwrite" placeholder="自定义抓单ID"></el-input>
              </div>
        	  <span slot="footer" class="dialog-footer">
        		<el-button @click="randomlog = false">取 消</el-button>
        		<el-button type="primary" @click="randomgo" :disabled="randomone">确 定</el-button>
        	  </span>
        </el-dialog>
		<el-dialog title="自定义产品类型":visible.sync="taglog" width="400px">
			  <div class="protag">
				  <el-tag :key="item.id" v-for="item in typelist" closable :disable-transitions="false" @close="handleClose(item.name)">{{item.name}}</el-tag>
					<el-input class="input-new-tag" v-if="inputVisible" v-model="inputValue" ref="saveTagInput" size="small" @keyup.enter.native="handleInputConfirm" @blur="handleInputConfirm">
					</el-input>
					<el-button v-else class="button-new-tag" size="small" @click="showInput">输入自定义名称</el-button>
			  </div>
			  <span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisible = false">取 消</el-button>
				<el-button type="primary" @click="dialogVisible = false">确 定</el-button>
			  </span>
		</el-dialog>
		<!-- <foot></foot> -->
	</div>
</template>

<script>
	import { provinceAndCityData, CodeToText, TextToCode } from 'element-china-area-data'
	import UploadExcelComponent from "@/components/UploadExcel/index.vue";
	import E from 'wangeditor'
	import axios from 'axios'
	import top from '@/components/top.vue'
	import left from '@/components/left.vue'
	import foot from '@/components/foot.vue'
	export default{
		components: {
			"left": left,
			"top": top,
			"foot": foot,
			UploadExcelComponent
		},
		name: 'myDistributor',
		data(){
			return{
				taglog:false,
				taglist:['类型1','类型2'],
				inputVisible: false,
				inputValue: '',

                keylog:false,
                keyv:[
                    {"key1":"","key2":"","key3":""}
                ],

				mingan:{
					city:"",
					citys:"",
					fixcitys:""
				},
				randomnum:"",
                jingdongrandom:"",
				search:"",
				msg:"hello",
				log:false,
				loading:true,

				typelist:{},
				citylist:provinceAndCityData,

				poollist:"",
                pool:"2",

                tracklist:"",
				form:{
                    tracking_company_id:"",
                    pool_id:"",
					produce_address:"",
					operator:"",
					name:"",
					sku:"",
					plan_type_id:"",
					province:"",
					city:[],
					citys:[],
					real_name_type:'0',
					produce_remark:"",
					status:"",
					comname:"",
					min_age:"",
					max_age:"",
					max_purchase:"-1",
					need_num:"0",

					haochinum:1,
					haochival:1,

					address_province:"",
					address_city:"",
					address_district:"",
					commission_rule:""
				},
				shopform:{
					product_id:"",
					title:"",
					status:"",
					parent_id:"",
					selling_point:"",
					commission_rule:"",
					is_need_photo:"0",
					description:"",
					image1:"",
					imageUrl: '',
					imageUrl2: '',
                    product_log_id:""
				},
                rules: {
                  operator: [{ required: true, message: '必选', trigger: 'change' }],
                  name: [{ required: true, message: '必填', trigger: 'blur' }],
                  sku: [{ required: true, message: '必填', trigger: 'blur' }],
                  city: [{ required: true, message: '请选择活动区域', trigger: 'change' }],
                  real_name_type: [{ required: true, message: '请输入', trigger: 'change' }],
                  randomnum: [{ required: true, message: '请输入抓单码', trigger: 'change' }],
                  title: [{ required: true, message: '必填', trigger: 'change' }],
                  is_need_photo: [{ required: true, message: '必选', trigger: 'change' }],
                  img: [{ required: true, message: '必选', trigger: 'change' }],
                  edit: [{ required: true, message: '必填', trigger: 'change' }],
                  visible: [{ required: true, message: '必选', trigger: 'change' }],
                  commission: [{ required: true, message: '必选', trigger: 'change' }],
                },
                abstract:"",
				moneyform:{
					order_page_id:"",
					visible:'1',
					commission:0,
					child_shop_ids:"",
					dislist:"",
					money:"",
					list:""
				},
				kejian:false,
				sub1:true,
				sub2:true,
				sub3:false,
                sub4:true,
				showmoney:false,
				sanlist:[
					// {name:"中国联通",id:10010},
					// {name:"中国移动",id:10086},
					// {name:"中国电信",id:10000},
					{name:"中国广电",id:10099}
				],
                randomvalue:"",
                randomone:false,
                randomlog:false,
                shop_id:"",
                statusshop:false,
				url:"",

				xiaomingtime:"",
				xiaomingying:""
			}
		},
		created() {
            //地址配置,用于下载模板
            if(window.location.href.indexOf("91haoka_platform") > -1){
            	console.log("线上项目，谨慎操作。")
            	this.url = window.location.origin+"/91haoka_platform/"
            }else{
            	this.url = ""
			}
			//小鸣莺家用
			var xiaomingying = JSON.parse(localStorage.getItem('USER'));
			this.xiaomingying = xiaomingying.id
            //获取56
            this.gettracklist()
			this.getlists()
			//获取分销商
			this.getdislist()
			//获取类型
			this.getproductstype();
			//随机生成10位数
            axios.get('/api/gth/user/shop')
                .then(response => {
                    if(response.data.msg.code == 0){
                        this.shop_id = response.data.data.shop_id
                    }else{
                        if(response.data.msg.code == 50401){that.$router.push({ path: "/login" }); return false}
                        that.$message.error(response.data.msg.info);
                    }
                })
		},
		mounted() {
			var that = this
			var editor = new E('#editor');
			editor.customConfig.uploadImgServer = '/upload'
			editor.customConfig.showLinkImg = false
			editor.customConfig.onchange = function (html) {
				that.shopform.description = html
			}
			editor.customConfig.customUploadImg = function (files, insert) {
				var formData = new FormData();
				formData.append("pic",files[0]);
				axios.post('/api/plan-market/order-page/upload-pic',formData)
					.then(response => {
						if(response.data.msg.code == 0){
							insert(response.data.data)
						}else{
							that.$message.error(response.data.msg.info);
						}
					})
			}
			editor.create();
			//获取产品详情
			this.getprodetail()

			//获取商品详情后追加内容
			var that = this;
			axios.get('/api/plan-market/order-page?order_page_id='+this.$route.query.id)
				.then(response => {
					if(response.data.msg.code == 0){
						var arr = ""
						for(var i in response.data.data.selling_point){
							arr = arr + response.data.data.selling_point[i]+'，'
						}
						response.data.data.selling_point = arr.substr(0, arr.length - 1);
						that.randomnum = response.data.data.fetch_code
                        that.jingdongrandom = response.data.data.fetch_code2
						that.shopform = response.data.data



                        if(response.data.data.status == 0){
                            that.statusshop = false
                        }else{
                            that.statusshop = true
                        }
						editor.txt.html(this.shopform.description)


                        that.loading = false
					}else{
						that.$message.error(response.data.msg.info);
					}
				})

		},
		methods:{

            //手动添加关键词
            keygo:function(){
                this.mingan.citys =[]
                this.mingan.fixcitys = []
                for(var i in this.keyv){
                    if(this.keyv[i].key1 != "" && this.keyv[i].key2 != "" && this.keyv[i].key3 != "" ){
                        this.mingan.citys.push(this.keyv[i].key1)
                        var k2 = this.keyv[i].key2
                        var k3 = this.keyv[i].key3
                        var obj={}
                        obj[k2] = k3
                        this.mingan.fixcitys.push(obj)
                    }
                }
                this.keylog = false
                console.log(this.mingan.citys)
                console.log(this.mingan.fixcitys)
            },
             //删除关键词
            keydel:function(i){
                this.keyv.splice(i,1);
            },
            //增加关键词
            addkey:function(){
                this.keyv.push({"key1":"","key2":"","key3":""})
            },
            //下载
            xiazai:function(){

            	const a = document.createElement('a');
            	a.setAttribute('download', '敏感地区模板.xlsx');
            	a.setAttribute('href', this.url+'static/mingandiqu.xlsx');
            	a.click();

            },

            //获取快递公司
            gettracklist:function(){
                var that = this
                axios.get('/api/plan-market/logistics-companies')
                	.then(response => {
                		that.tracklist = response.data.data
                	})
            },
            //获取号池
            getlists:function(){
                var that = this
                axios.get('/api/plan-market/pool/list?page=1&page_size=1000&status=1')
                	.then(response => {
                		that.poollist = response.data.data.data
                	})
            },
			//自定义抓单码唯一性
			randomnumwrite:function(){
			    var that = this
			    axios.get('/api/plan-market/order-page/fetch-code/isexist?fetch_code='+this.randomvalue)
			        .then(response => {
			            if(response.data.msg.code == 0){
			                that.randomone = false
			            }else{
			                that.randomone = true
			            }
			        })
			},
			//自定义抓单码点击确认
			randomgo:function(){
			    this.randomnum = this.randomvalue
			    this.randomlog = false
			},
			//获取产品详情
			getprodetail:function(){
				var that = this;
				axios.get('/api/plan-market/product?product_id='+this.$route.query.productid)
					.then(response => {
						if(response.data.msg.code == 0){
							this.form = response.data.data

                            //查看有没有号池的id  没有就是没关联
                            if(this.form.pool_id != 0){
                                this.pool = "1"
                            }else{
                                 this.pool = "2"
                                 this.form.pool_id = ""
                            }
                            //敏感地区
							this.mingan.citys = this.form.warn_province
							this.mingan.fixcitys = this.form.warn_city

                            for( var i in this.mingan.citys){
                                this.keyv.push({"key1":"","key2":"","key3":""})

                            }
                            for(var m in this.keyv){
                                this.keyv[m].key1 = this.mingan.citys[m]

                                for(var n in this.mingan.fixcitys[m]){
                                    this.keyv[m].key2 = n
                                    this.keyv[m].key3 = this.mingan.fixcitys[m][n]
                                }
                            }

							var city = []
							if(this.form.province != ""){
								city.push(TextToCode[this.form.province].code)
							}
							if(this.form.city != ""){
								city.push(TextToCode[this.form.province][this.form.city].code)
							}
							this.form.citys = city

							this.xiaomingtime = response.data.data.max_purchase_time

						}else{
							that.$message.error(response.data.msg.info);
						}
					})
			},

			//获取商品品详情
			getshopdetail:function(){
				var that = this;
				axios.get('/api/plan-market/order-page?order_page_id='+this.$route.query.id)
					.then(response => {
						if(response.data.msg.code == 0){
							var arr = ""
							for(var i in response.data.data.selling_point){
								arr = arr + response.data.data.selling_point[i]
							}
							response.data.data.selling_point = arr

							that.randomnum = response.data.data.fetch_code
							that.shopform = response.data.data

						}else{
							that.$message.error(response.data.msg.info);
						}
					})
			},


			//修改佣金时执行全部佣金赋值并保存后重新获取一下列表和佣金
			fixallmoney:function(){
				var that = this;
				var formData = new FormData();
				formData.append("order_page_id",this.moneyform.order_page_id);
				formData.append("visible",this.moneyform.visible);
				formData.append("commission",this.moneyform.commission);
				formData.append("child_shop_ids",this.moneyform.child_shop_ids);

				axios.post('/api/gth/order-page/visible',formData)
					.then(response => {
						if(response.data.msg.code == 0){
							that.getmoneylist();
						}else{
							that.$message.error(response.data.msg.info);
						}
					})
			},
			//个性化编辑佣金
			fixmoney:function(i,id){
				this.$prompt('请输入金额', '提示', {
				  confirmButtonText: '确定',
				  cancelButtonText: '取消',
				}).then(response => {
					var that = this;
					var formData = new FormData();
					formData.append("order_page_id",that.moneyform.order_page_id);
					formData.append("child_shop_id",id);
					formData.append("commission",response.value);

					axios.post('/api/plan-market/order-page/commissions/update',formData)
						.then(response => {
							if(response.data.msg.code == 0){
								this.getmoneylist();
								that.$message({
								  message: '保存成功！',
								  type: 'success'
								});
							}else{
								that.$message.error(response.data.msg.info);
							}
						})
				})
			},
			//获取分销商和佣金
			getmoneylist:function(){
				var that = this;
				axios.get('/api/plan-market/order-page/commissions?order_page_id='+that.moneyform.order_page_id)
					.then(response => {
						if(response.data.msg.code == 0){
							that.moneyform.list = response.data.data.data
						}else{
							that.$message.error(response.data.msg.info);
						}
					})
			},

			chakan:function(){
				console.log(this.moneyform.child_shop_ids)
			},
			//产品名验证唯一性
			nijiushiwodeweiyi1:function(){
				var that = this;
				axios.get('/api/plan-market/product/name/isexist?name='+that.form.name)
					.then(response => {
						if(response.data.msg.code == 0){
							this.sub1 = true
						}else{
							this.sub1 = false
							that.$message.error(response.data.msg.info);
						}
					})
			},
			//产品编号验证唯一性
			nijiushiwodeweiyi2:function(){
				var that = this;
				axios.get('/api/plan-market/product/sku/isexist?sku='+this.form.sku)
					.then(response => {
						if(response.data.msg.code == 0){
							this.sub2 = true
						}else{
							this.sub2 = false
							that.$message.error(response.data.msg.info);
						}
					})
			},
			//商品名验证唯一性
			nijiushiwodeweiyi3:function(){
				var that = this;
				axios.get('/api/plan-market/order-page/name/isexist?title='+this.shopform.title)
					.then(response => {
						if(response.data.msg.code == 0){
							this.sub3 = true
						}else{
							this.sub3 = false
							that.$message.error(response.data.msg.info);
						}
					})
			},
            //京东唯一性
            nijiushiwodeweiyi4:function(){
				this.jingdongrandom = this.jingdongrandom.trim()
                if(this.jingdongrandom == ""){
                    this.sub4 = true
                }else{
                   var that = this;
                   axios.get('/api/plan-market/order-page/fetch-code?fetch_code2='+this.jingdongrandom)
                   	.then(response => {
                   		if(response.data.msg.code == 0){
                   			this.sub4 = true
                   		}else{
                   			this.sub4 = false
                   			that.$message.error(response.data.msg.info);
                   		}
                   	})
                }

            },
			//身份证审核
			cardid:function(){
				this.moneyform.child_shop_ids = "";
				if(this.moneyform.visible == 3 || this.moneyform.visible == 4){this.kejian = true}
				if(this.moneyform.visible == 1 || this.moneyform.visible == 2){this.kejian = false}
			},
			//获取全部分销商
			getdislist:function(){
				var that = this;
				axios.get('/api/gth/partner/list?page_size=10000')
					.then(response => {
						if(response.data.msg.code == 0){
							that.moneyform.dislist = response.data.data.data
						}else{
							that.$message.error(response.data.msg.info);
						}
					})
			},
			//保存产品
			productsave:function(){

				if(this.sub1 == false || this.sub2 == false || this.sub4 == false || this.form.name == "" || this.form.sku == ""){
					return false
				}
				//发布还是仅保存
                console.log(this.jingdongrandom)
                if(this.jingdongrandom == "" || this.jingdongrandom == null){

                }else{
                    if(this.jingdongrandom.length != 3 ){
                        this.$message.error("京东抓单码必须三位或者不填写");
                        return false
                    }
                }

				if(this.form.address_province == undefined){
					this.form.address_province = this.form.province
					this.form.address_city = this.form.city
				}

				var that = this;
				var formData = {
					product_id:this.$route.query.productid,
					name:this.form.name,
					sku:this.form.sku,
					operator:this.form.operator,
					plan_type_id:this.form.plan_type_id,
					province:this.form.address_province,
					city:this.form.address_city,
					real_name_type:this.form.real_name_type,
					produce_remark:this.form.produce_remark,
					max_purchase:this.form.max_purchase,
					min_age:this.form.min_age,
          max_age:this.form.max_age,
					// status:this.form.status,
					produce_address:this.form.produce_address,
					commission_rule:this.form.commission_rule,
					warn_province:this.mingan.citys,
					warn_city:this.mingan.fixcitys,
          tracking_company_id:this.form.tracking_company_id,
          abstract:this.abstract,
					need_num:this.form.need_num,
					max_purchase_time:this.xiaomingtime
				}
                if(this.pool == 1 ){
                    formData.pool_id = this.form.pool_id
                }
				axios.post('/api/plan-market/product',formData)
					.then(response => {
						if(response.data.msg.code == 0){
                           that.shopform.product_id = response.data.data.id

                           that.shopform.product_log_id= response.data.data.product_log_id
							//成功获取到产品id后执行保存商品
							that.shopsave();

						}else{
							that.$message.error(response.data.msg.info);
						}
					})
			},
			//保存商品
			shopsave:function(){
				var that = this;
				var formData = {
					order_page_id:this.$route.query.id,
					title:this.form.name,
					product_id:this.shopform.product_id,
					selling_point:this.shopform.selling_point,
					commission_rule:this.shopform.commission_rule,
					is_need_photo:this.shopform.is_need_photo,
					description:this.shopform.description,
					image1:this.shopform.image1,
					fetch_code:this.form.sku,
					status:this.shopform.status,
          abstract:this.abstract,
          fetch_code2:this.jingdongrandom,
          product_log_id:this.shopform.product_log_id
				}

				axios.post('/api/plan-market/order-page',formData)
					.then(response => {
                        //修改商品（落基审核）
                        if(response.data.msg.code == 0){

                            if(that.form.status == 0){
                                that.$message({
                                  message: '修改成功！',
                                  type: 'success'
                                });
                                that.$router.push({
                                    path: '/productionDelivery/productionDeliverysale'
                                })
                            }else{

                               if( this.shop_id == 50481 || this.shop_id == 304676){
                                    if(this.statusshop == true){
                                        that.$message({
                                           message: '商品已提交审核！',
                                           type: 'success'
                                        });
                                        that.$router.push({
                                           path: '/productionDelivery'
                                        })
                                    }else{
                                        that.$message({
                                          message: '修改成功！',
                                          type: 'success'
                                        });
                                        that.$router.push({
                                            path: '/productionDelivery'
                                        })
                                    }

                               }else{
                                 that.$message({
                                   message: '修改成功！',
                                   type: 'success'
                                 });
                                 that.$router.push({
                                     path: '/productionDelivery'
                                 })
                               }
                            }

                        }else{
                                that.$message.error(response.data.msg.info);
                        }
					})
			},

			//绑定佣金分销商
			bangding:function(){
				var that = this;
				var formData = new FormData();
				formData.append("order_page_id",this.moneyform.order_page_id);
				formData.append("visible",this.moneyform.visible);
				formData.append("commission",this.moneyform.commission);
				formData.append("child_shop_ids",this.moneyform.child_shop_ids);

				axios.post('/api/gth/order-page/visible',formData)
					.then(response => {
						if(response.data.msg.code == 0){
							that.$message({
							  message: '恭喜你，修改商品成功！',
							  type: 'success'
							});
						}else{
							that.$message.error(response.data.msg.info);
						}
					})
			},

			//单个图片上传
			uploadok:function(file){
				var that = this;
				var formData = new FormData();
				formData.append("pic",file.raw);
				axios.post('/api/plan-market/order-page/upload-pic',formData)
					.then(response => {
						if(response.data.msg.code == 0){
							that.shopform.image1 = response.data.data
						}else{
							that.$message.error(response.data.msg.info);
						}
					})
			},
			//选择省市区
			changeaddress:function(v){
				this.form.address_province = CodeToText[v[0]],
				this.form.address_city = CodeToText[v[1]]
			},
			//导入敏感地区
			exportData:function(data) {

				this.mingan.citys = []
				this.mingan.fixcitys = []
				for(var i = 0 ;i < data.results.length; i++){
					this.mingan.citys.push(data.results[i]['敏感地区'])

					if(data.results[i]['修改敏感地区'].indexOf(",") > -1){
						var arr = data.results[i]['修改敏感地区'].split(',')
					}
					else if(data.results[i]['修改敏感地区'].indexOf("，") > -1){
						var arr = data.results[i]['修改敏感地区'].split('，')
					}
					else{
						return false
						that.$message.error("数据出错了，请检查格式");
					}
					var obj = {}
					obj[arr[0]] = arr[1]
					this.mingan.fixcitys.push(obj)

			        var obj2 = {}
			        obj2['key1'] = data.results[i]['敏感地区']
			        obj2['key2'] = arr[0]
			        obj2['key3'] = arr[1]

			       this.keyv.push(obj2)
				}
			    console.log(this.mingan.citys)
			    console.log(this.mingan.fixcitys)
				this.$message({
				  message: '导入成功，共计'+this.mingan.citys.length+'条',
				  type: 'success'
				});
			},
			//获取产品类型
			getproductstype:function(){
				var that = this
				axios.get("/api/gth/plan-type")
				  .then(function(response) {
					  if(response.data.msg.code == 0){
					  	that.typelist = response.data.data
					  }else{
					  	that.$message.error(response.data.msg.info);
					  }

				  })
			},

			loggo:function(){
				console.log("a")
			},

			//自定义产品类型
			handleClose(tag) {
				this.taglist.splice(this.taglist.indexOf(tag), 1);
			},

			showInput() {
				this.inputVisible = true;
				this.$nextTick(_ => {
				  this.$refs.saveTagInput.$refs.input.focus();
				});
			},

			handleInputConfirm() {
				var that = this;
				var formData = new FormData();
				formData.append("name",this.inputValue);
				axios.post('/api/gth/plan-type/release',formData)
					.then(response => {
						if(response.data.msg.code == 0){
							that.getproductstype();
							that.$message({
							  message: '添加成功',
							  type: 'success'
							});
						}else{
							that.$message.error(response.data.msg.info);
						}
					})
				let inputValue = this.inputValue;
				if (inputValue) {
				  this.taglist.push(inputValue);
				}
				this.inputVisible = false;
				this.inputValue = '';
			}
		}

	}
</script>

<style lang="scss" scoped>
	/deep/ .w-e-menu{ z-index: 1001 !important;}
	/deep/ .w-e-text-container{z-index: 1000 !important; }
	.index{
    /deep/ .el-message-box__wrapper{ z-index: 20000 !important;}
		.xiaoming{ display: flex;
			.el-form-item{ flex: 1;}
		}
		// #editor{
        //     .w-e-text-container{ z-index: 1999 !important;}
        //     .w-e-menu{ z-index: 1999 !important;}
        // }

		.loglist{
			display: flex; justify-content: space-between; margin-bottom: 30px;
			.log_title{ padding: 7px 10px;}
		}
		.listl{ height: 350px; overflow: auto;
			/deep/ .el-input__inner{ border: none; text-align: center}
		}
		.list{

			display: flex; text-align: center; color: #727272; line-height: 45px; border: 1px #EAEAEA solid; margin-top: -1px;
			.th{ flex: 1; background: #F9F9F9; font-size: 14px; }
			.td{ flex: 1; font-size: 14px; border-right:1px #EAEAEA solid; }
		}
		/deep/ .el-pagination{ text-align: right; margin: 20px 0}
		/deep/ .el-dialog__wrapper{ z-index: 19999 !important;}
		.keyd{
		    display: flex;
		    /deep/ .is-plain{ height: 30px; line-height: 30px; padding: 0 10px; margin-left: 10px; }
		    #drop{
		    	/deep/ .el-button--primary{ background: #409EFF; border: 1px #409eff solid; height: 30px; line-height: 30px; padding: 0 20px;}
		    }
		}
		.protag{
			/deep/ .el-tag{ margin-right: 20px; margin-bottom: 20px;}
		}
		.addpro{
			 width: 1166px;
			.el-steps{ width: 100%;  padding: 30px;}
			.step{ margin-bottom: 20px; background: #FFFFFF;
				.redbor{
					/deep/ .el-input__inner{border: 1px #EEF7FF solid;}
				}
				.tilte{ background: #F9F9F9; padding-left: 30px; line-height: 45px; font-size: 14px;
					span{ background: #B1E4FF; color: #FFFFFF; float: right; line-height: 15px; cursor: pointer; padding: 5px 0; display: block; width: 24px; text-align: center; margin-right: 20px; margin-top: 8px; border-radius: 14px;}
				}
				.w330{
					/deep/ .el-input__inner{ width: 330px !important;}
				}
				.w480{
					/deep/ .el-input__inner{ width: 480px !important;}
				}
				.con{ background: #FFFFFF; padding: 35px;
					.flex{ display: flex;}
					.ori{ background: #FBFBFB; padding: 20px 10px;
						/deep/ .el-input{ width: 300px;}
						/deep/ .el-form-item{ margin-bottom: 20px;}
						/deep/ .el-form-item__label{ width: 150px !important;}
						.age /deep/ .el-input{ width: 150px;}
						.wenhao2{color: #999; font-size: 14px;}
						.no{
							display: flex; align-items: center;
							#drop{
								.el-button--primary{ background: #409EFF;border: 1px #409EFF solid;}
							}
							.nonum{ background: #409EFF; padding: 0px 10px; line-height: 35px; height: 35px; color: #FFFFFF; border-radius: 3px; display: block;}
							.el-button{ }
							span{ margin: 0 20px;}
						}

					}
				}
				.haochi{
				    /deep/ .el-radio__label{ line-height: 40px;}
					/deep/ .el-select{ margin-left: 20px;}
				}
				.btm0 {
					/deep/ .el-button{ margin-left: 20px;}
					/deep/ .el-form-item{ margin-bottom: 0;}
				}
				.label200 .el-form-item__label{ width: 149px !important;}
				.avatar-uploader .el-upload {
					border: 1px dashed #d9d9d9;
					border-radius: 6px;
					cursor: pointer;
					position: relative;
					overflow: hidden;
				  }
				  .avatar-uploader .el-upload:hover {
					border-color: #409EFF;
				  }
				  .avatar-uploader-icon {
					font-size: 28px;
					color: #8c939d;
					width: 178px;
					height: 178px;
					line-height: 178px;
					text-align: center;
				  }
				  .avatar {
					width: 178px;
					height: 178px;
					display: block;
				  }
				.wenhao{ background: #B1E4FF; color: #FFFFFF; line-height: 15px; cursor: pointer; padding: 5px 11px; margin-left: 20px; text-align: center;  border-radius: 14px;}
			}

		}
	}
</style>
